package com.wanglibao.woodtrade.woodtrade.ui.fragment.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wanglibao.woodtrade.woodtrade.R;
import com.wanglibao.woodtrade.woodtrade.model.ShopOrder;
import com.wanglibao.woodtrade.woodtrade.util.DateUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class ItemLvMessageHomeFragemntAdapter extends BaseAdapter {

    private List<ShopOrder> objects = new ArrayList<ShopOrder>();

    private Context context;
    private LayoutInflater layoutInflater;

    public ItemLvMessageHomeFragemntAdapter(Context context,List<ShopOrder> list) {
        this.context = context;
        this.objects=list;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public ShopOrder getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.item_lv_message_home_fragemnt, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        initializeViews((ShopOrder)getItem(position), (ViewHolder) convertView.getTag());
        return convertView;
    }

    private void initializeViews(ShopOrder object, ViewHolder holder) {
        //TODO implement
        holder.tvItemFragmentHomeMessage.setText(object.initTitle(object));
        holder.tvItemFragmentHomeMessageDate.setText(DateUtils.getTimeDifference(object.pay_time));
    }

    static class ViewHolder {
        @Bind(R.id.tv_item_fragment_home_message) TextView tvItemFragmentHomeMessage;
    @Bind(R.id.tv_item_fragment_home_message_date) TextView tvItemFragmentHomeMessageDate;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
